package com.springsummer.information.green.beans;


import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public abstract class AbstractBeanFactory implements ConfigurableBeanFactory {

    //protected  List<BeanPostProcessor> beanPostProcessors =new ArrayList<>();

    protected Map<String, BeanPostProcessor> beanPostProcessors = new LinkedHashMap<>();

    @Override
    public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) {
        // Remove from old position, if any
        String processorName = beanPostProcessor.getClass().getName();
        this.beanPostProcessors.remove(processorName);
        this.beanPostProcessors.put(processorName, beanPostProcessor);
    }


    @Override
    public boolean containsBeanPostProcessor(BeanPostProcessor postProcessor) {
        String processorName = postProcessor.getClass().getName();
        return beanPostProcessors.containsKey(processorName);
    }

    @Override
    public int getBeanPostProcessorCount() {
        return this.beanPostProcessors.size();
    }

    public List<BeanPostProcessor> getBeanPostProcessors() {
        List<BeanPostProcessor> list = new ArrayList<>();
        list.addAll(beanPostProcessors.values());
        return list;
    }

}
